<?php

namespace app\store\model;
use app\common\model\UserInfo as UserInfoModel;
use app\store\model\ProjectTasks;
class UserInfo extends UserInfoModel
{
    /**
     * 获取列表
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($param)
    {
        $where = [];
        if(!empty($param['company_id'])){
            $where['ui.company_id'] = $param['company_id'];
        }
        return $this->alias('ui')->field("ui.*,d.division_name,b.job_name")->join('division d','ui.division_id=d.id','left')->join('job b','ui.job_id=b.id','left')->where($where)->order(['ui.create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => request()->request()
            ]);

    }
    /**
     * 新增记录
     * @param $data
     * @return false|int
     */
    public function add($data)
    {
        //$data['wxapp_id'] = self::$wxapp_id;
        return $this->allowField(true)->save($data);
    }
    /**
     * 更新记录
     * @param $data
     * @return bool|int
     */
    public function edit($data,$id)
    {
        return $this->allowField(true)->save($data,['id'=>$id]) !== false;
    }
    /**
     * 删除文章
     * @param $article_id
     * @return array
     * @throws \think\exception\DbException
     */
    public static function del($id)
    {
        return self::destroy($id);
    }

    /**
     * 更新用户任务信息
     * @throws \think\db\exception\BindParamException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function updateTask(){
        $tasks = new ProjectTasks();
        $data = self::all();
        if(!empty($data)){
            foreach ($data as $item){
                $row = $tasks->information($item->id);
                if(!empty($row)){
                    foreach ($row as $val){
                        if(!empty($val['entry_name']) && $val['entry_name']!='default'){
                            $item[$val['entry_name']] = $val['type_num'];
                        }
                    }
                }
                //print_r($item->toArray());
               $item->save();
            }
        }
    }

}